package com.htht.job.admin.controller.product;

import com.alibaba.fastjson.JSON;
import com.htht.job.core.api.parameter.ParameterService;
import com.htht.job.core.api.treenode.TreeNodeService;
import com.htht.job.core.biz.model.ReturnT;
import com.htht.job.core.util.ResultUtil;
import com.htht.job.core.util.ReturnCodeEnum;
import com.htht.job.executor.model.parameter.ParameterModel;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.ui.Model;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.ResponseBody;

import java.util.Map;

@Controller
@RequestMapping("/processmodel")
public class ProcessController {
	@Autowired
	private TreeNodeService treeNodeService;
	@Autowired
	private ParameterService parameterService;
	@RequestMapping
	public String index(Model model) {
		return "/processmeta/processmeta.index";
	}
	
	
	@RequestMapping("/save")
	@ResponseBody
	public ReturnT<String>  save(ParameterModel parameterModel){
		ResultUtil resultUtil=new ResultUtil();
		ParameterModel p=parameterService.saveParameter(parameterModel);
		if(null!=p.getId()){
			return ReturnT.SUCCESS;
		}else{
			return ReturnT.FAIL;
		}
	}
	
	@RequestMapping("/pageList")
	@ResponseBody
	public Map<String, Object> pageList(@RequestParam(required = false, defaultValue = "0") int start,  
			@RequestParam(required = false, defaultValue = "10") int length,ParameterModel parameterModel) {

		if(start!=0){
			start=start/length;
		}
		return parameterService.pageList(start, length,parameterModel);
	}
	@RequestMapping("/deleteParameter")
	@ResponseBody
	public ReturnT<String> deleteParameter(String id){
		return parameterService.deleteParameter(id);
	}
	
}
